Post

Replies

Boosts

Views

Created

PDFPage thumbnail (UIImage) does not respect PDFPage orientation in iOS 13 (Xcode 13.1)
Description I am having issue with UIImage "generated" from PDFPage via method .thumbnail(of:for). UIImage, which I later display in UIImageView does not respect rotation of the PDF page, but for iOS 13 only. When PDF page is rotated for example by 90° and presented in PDFView all is good and shown correctly. But when I want to take the UIImage (i.e. thumbnail) of the PDFPage and show it in UIImageView, for some reason, iOS 13 does not respect the initial rotation of the PDF page and present it in UIImageView incorrectly. Please behold on below sample code and example screenshots. Testing environment iOS 13 on simulator only, not having real device Xcode 13.1 Sample code for sake of shorter example, I force unwrap where optionals occur import UIKit import PDFKit class TestingViewController: UIViewController { lazy var imageView: UIImageView = { let iv = UIImageView() iv.translatesAutoresizingMaskIntoConstraints = false return iv }() // Pass URL of the PDF document when instantiating this VC init(withURL: URL) { super.init(nibName: nil, bundle: nil) let pdfDoc = PDFDocument(url: withURL) let pdfPage = pdfDoc!.page(at: 0) // Getting first page of the doc let pdfPageRect = pdfPage!.bounds(for: .mediaBox) imageView.image = pdfPage!.thumbnail(of: pdfPageRect.size, for: .mediaBox) // Getting the UIImage of the PDF page and assign it to the needed image view imageView.contentMode = .scaleAspectFit imageView.clipsToBounds = true print("\(pdfPage?.rotation)") // Prints the correct rotation value, even though UIImageView does not respect it } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } // Layout only override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemPink view.addSubview(imageView) NSLayoutConstraint.activate([ imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor), imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor), imageView.widthAnchor.constraint(equalToConstant: 350), imageView.heightAnchor.constraint(equalToConstant: 700), ]) } } Example screenshots from simulator ✅ Presented correctly (iOS 15) ❌ Presented incorrectly (iOS 13.2)
0
0
1.5k
Jan ’22
Custom color of VNDocumentCameraViewController document detecting frame (Auto-Shutter)
Is it possible to change "Auto shutter" color programmatically of VNDocumentCameraViewController class? By Auto-Shutter I mean that feature that it will automatically detect the document make that frame looking for perfect scan shape. As a default color is set blue color, but I noticed the native iOS Notes app has this document detecting frame rather yellowish, I am curious if there is any way how to change that.
1
0
855
Apr ’21